getBlogDetail();
//获取博客信息
function getBlogDetail(){
    var blogId = location.search;
    $.ajax({
        type: "get",
        url: "/blog/getblogdetail"+location.search,
        success: function (ret){
            if(ret.code!=200 || ret.data==null){
                if(ret.code == -1) {
                    alert(ret.errMge);
                }
                return ;
            }
            var blogdetail = ret.data;
            $(".right .content .title").text(blogdetail.title);
            $(".right .content .date").text(blogdetail.createTime);
            //$(".right .content .detail").html(blogdetail.content);
            $(".right .content .detail").empty();
            editormd.markdownToHTML("detail", {
                markdown: ret.data.content,
            });

            var locatUserId = localStorage.getItem("loginUserId");
            if(locatUserId == ret.data.userId){
                let finalHtml = '<button onclick="window.location.href=\'blog_update.html?blogId='+ret.data.id+'\'">编辑</button>';
                finalHtml += '<button onclick="deleteBlog('+ret.data.id+')">删除</button>';
                console.log(finalHtml);
                $(".content .operating").html(finalHtml);
            }
        }
    });
}


//删除博客
function deleteBlog(blogId) {
    const isConfirmed = confirm('确定删除这篇博客?');
    if(isConfirmed){
        $.ajax({
            type: "post",
            url: "/blog/delete?blogId="+blogId,
            success: function (ret){
                if(ret.code == 200 && ret.data == true){
                    location.href = "blog_list.html";
                }else {
                    alert("博客删除失败，"+ret.errMge);
                }
            }
        });
    }
}






